package cn.slipi.common.response;

import cn.slipi.common.enums.ResponseCode;
import lombok.Data;

@Data
public class Response<T> {
    private Integer code;
    private String msg;
    private T data;

    public static Response success() {
        Response response = new Response();
        response.setResponseCode(ResponseCode.SUCCESS);
        return response;
    }

    public static Response success(Object data) {
        Response response = new Response();
        response.setResponseCode(ResponseCode.SUCCESS);
        response.setData(data);
        return response;
    }

    public static Response success(ResponseCode responseCode, Object data) {
        Response response = new Response();
        response.setResponseCode(responseCode);
        response.setData(data);
        return response;
    }

    public static Response fail() {
        Response response = new Response();
        response.setResponseCode(ResponseCode.FAIL);
        return response;
    }

    public static Response fail(Integer code, String msg) {
        Response response = new Response();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public void setResponseCode(ResponseCode responseCode) {
        this.code = responseCode.code();
        this.msg = responseCode.msg();
    }
}
